package com.zhang.family_doctor.controller;

import com.github.pagehelper.PageInfo;
import com.zhang.family_doctor.entity.Mechanism;
import com.zhang.family_doctor.entity.R;
import com.zhang.family_doctor.service.MechanismService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 机构管理模块
 */
@RestController
@RequestMapping("mechanism")
@Slf4j
@Api(tags = "机构管理模块")
public class MechanismController {

    @Autowired
    private MechanismService mechanismService;

    @ApiOperation("新增机构")
    @PostMapping("/save")
    public R<String> save(@RequestBody Mechanism mechanism){
        log.info("新增机构：{}",mechanism);
        return mechanismService.save(mechanism);
    }

    @ApiOperation("修改机构")
    @PostMapping("/update")
    public R<String> update(@RequestBody Mechanism mechanism){
        log.info("修改机构：{}",mechanism);
        return mechanismService.update(mechanism);
    }

    @ApiOperation("分页查询机构")
    @GetMapping("/getList")
    public R<PageInfo<Mechanism>> getList(Integer pageNum, Integer pageSize,String companyName){
        log.info("分页查询机构：{}",pageNum,pageSize,companyName);
        return mechanismService.getList(pageNum,pageSize,companyName);
    }

    @ApiOperation("根据id删除机构")
    @DeleteMapping("/delete")
    public R<String> delete(Integer id){
        log.info("根据id删除机构：{}",id);
        return mechanismService.delete(id);
    }

    @ApiOperation("禁用或启用")
    @GetMapping("/updateStateById")
    public R<String> updateStateById(Integer id,Integer state){
        log.info("禁用或启用：{}",id,state);
        return mechanismService.updateStateById(id,state);
    }

}
